package com.qianying.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qianying.comment.CommonResult;
import com.qianying.entity.OrderResponseTime;
import com.qianying.mapper.OrderResponseTimeMapper;
import com.qianying.service.OrderResponseTimeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderResponseTimeServiceImpl extends ServiceImpl<OrderResponseTimeMapper, OrderResponseTime> implements OrderResponseTimeService {

    @Resource
    private OrderResponseTimeMapper orderResponseTimeMapper;


    @Override
    public CommonResult<?> insert(OrderResponseTime record) {
        if (record == null) {
            return CommonResult.failed("订单响应对对象不能为空！");
        }
        Boolean isOk = this.save(record);
        if (isOk) {
            return CommonResult.success(record.getId(), "插入成功");
        } else {
            return CommonResult.failed();
        }
    }

    @Override
    public CommonResult<?> deleteByPrimaryKey(Long id) {
        Boolean isOk = this.removeById(id);
        if (isOk) {
            return CommonResult.success("删除成功！");
        } else {
            return CommonResult.failed("删除失败！");
        }
    }

    @Override
    public CommonResult<?> updateByPrimaryKey(OrderResponseTime record) {
        if (record == null || record.getId() == null) {
            return CommonResult.failed("跟新对象或者id不能为空！");
        }
        Boolean isOk = this.updateById(record);
        if (isOk) {
            return CommonResult.success("更新成功！");
        } else {
            return CommonResult.failed("更新失败！");
        }
    }

    @Override
    public CommonResult<?> selectByPrimaryKey(Integer id) {
        return null;
    }

    @Override
    public CommonResult<?> selectAllByCustomId(Long customId) {
        if (customId == null) {
            return CommonResult.failed("客户id不能为空!");
        }
        List<OrderResponseTime> list = orderResponseTimeMapper.selectAllByCustomId(customId);
        if (list.isEmpty()) {
            return CommonResult.failed("查询到的结果是空的!");
        }
        return CommonResult.success(list, "查询成功！");
    }
}